<template>
  <el-dialog :visible="showRoleDialog" title="分配角色" @close="cancelDialog">
    <el-checkbox-group v-model="ids" style="margin-bottom: 20px">
      <el-checkbox v-for="item in roleList" :key="item.id" :label="item.id">
        {{ item.name }}
      </el-checkbox>
    </el-checkbox-group>
    <el-row type="flex" justify="center">
      <el-button type="primary" @click="saev">确定</el-button>
      <el-button @click="cancelDialog">取消</el-button>
    </el-row>
  </el-dialog>
</template>

<script>
import { getsUser } from '@/api/user'
import { getRoleList } from '@/api/setting'
import { assignRoles } from '@/api/employees'

export default {
  name: 'role',
  props: {
    showRoleDialog: {
      type: Boolean,
      default: false
    },
    currentId: {
      type: String,
      default: '',
      require: true
    }
  },

  data () {
    return {
      //
      ids: [],
      roleList: []
      //弹窗显示
    }
  },
  methods: {
    //分配角色确认按钮事件
    async saev () {
      await assignRoles({
        id: this.currentId,
        roleIds: this.ids
      })
      this.$message.success('分配成功')
      this.$emit('update:showRoleDialog', false)
    },
    //   取消按钮事件
    cancelDialog () {
      this.ids = []
      this.$emit('update:showRoleDialog', false)
    },
    // 获取角色列表
    async getRoleList () {
      let res = await getRoleList({
        page: 1,
        pagesize: 99999
      })
      this.roleList = res.data.rows
    },
    //默认选中列表事件
    async getUserProfile (id) {
      let res = await getsUser(id)
      this.ids = res.data.roleIds
    }
  },
  created () {
    this.getRoleList()
  }
}
</script>

<style></style>
